//
//  EWmapLine.m
//  mkMapTest0
//
//  Created by 鱼 bin on 12-6-7.
//  Copyright 2012 __MyCompanyName__. All rights reserved.
//

#import "EWmapLine.h"


@implementation UIColor(UIColorExtend)

-(unsigned int)colorToUint{
	unsigned int data = 0;
	unsigned char* charP = (unsigned char*)&data;
	const CGFloat* frgba = CGColorGetComponents([self CGColor]);
	
	charP[0] = frgba[0]*255;
	charP[1] = frgba[1]*255;
	charP[2] = frgba[2]*255;
	charP[3] = frgba[3]*255;
	
	return data;
}

+(UIColor*)uintToColor:(unsigned int)_data{
	
	unsigned char* charP = (unsigned char*)&_data;
	float fR = charP[0]/255.0;
	float fG = charP[1]/255.0;
	float fB = charP[2]/255.0;
	float fA = charP[3]/255.0;
	UIColor* color = [UIColor colorWithRed:fR green:fG blue:fB alpha:fA];
	return color;
}

@end



@implementation EWmapLine


@synthesize color;
@synthesize polyline;

-(id)initWithCoordinates:(CLLocationCoordinate2D *)coords count:(NSUInteger)count{
	self = [super init];
	polyline = [MKPolyline polylineWithCoordinates:coords count:count];
	[polyline retain];
	return self;
}

-(void)dealloc{
	[polyline release];
	[super dealloc];
}


+(UIColor*)getUIColorWithStr:(NSString*)colorStr{
	BOOL hasIt = NO;
	UIColor* _color;
	if ([colorStr isEqualToString:@"#redLine"]) {
		_color = [UIColor redColor];
		hasIt = YES;
	}
	if ([colorStr isEqualToString:@"#blueLine"]) {
		_color = [UIColor blueColor];
		hasIt = YES;
	}
	if ([colorStr isEqualToString:@"#yellowLine"]) {
		_color = [UIColor yellowColor];
		hasIt = YES;
	}
	if ([colorStr isEqualToString:@"#whiteLine"]) {
		_color = [UIColor whiteColor];
		hasIt = YES;
	}
	
	if (!hasIt) {
		_color = [UIColor redColor];
		NSLog(@"cant find color:%@  set default redColor",colorStr);
	}	
	return _color;
}



+ (EWmapLine *)maplineWithCoordinates:(CLLocationCoordinate2D *)coords count:(NSUInteger)count{
	
	id line = [[EWmapLine alloc] initWithCoordinates:coords count:count];
	
	return [line autorelease];
}

#pragma mark MKOverlay
//@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
- (CLLocationCoordinate2D) coordinate {
    return [polyline coordinate];
}

//@property (nonatomic, readonly) MKMapRect boundingMapRect;
- (MKMapRect) boundingMapRect {
    return [polyline boundingMapRect];
}

- (BOOL)intersectsMapRect:(MKMapRect)mapRect {
    return [polyline intersectsMapRect:mapRect];
}


@end
